package android.theHead;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.util.Log;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class MapItemizedOverlay extends ItemizedOverlay {
	private ArrayList<HeadOverlayItem> mOverlays = new ArrayList<HeadOverlayItem>();
	Context mContext;

	public MapItemizedOverlay(Drawable defaultMarker, Context context) {
		super(boundCenterBottom(defaultMarker));
		mContext = context;
	}

	@Override
	protected OverlayItem createItem(int i) {
		return mOverlays.get(i);
	}
	
	public void clear(){
		mOverlays.clear();
	}

	@Override
	public int size() {
		return mOverlays.size();
	}
	
	public void addOverlay(HeadOverlayItem overlay) {
	    mOverlays.add(overlay);
	    populate();
	}
	
	@Override
	public boolean onTap(int index) {
		final HeadOverlayItem item = mOverlays.get(index);
		AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
		
		dialog.setTitle(item.getTitle());
		dialog.setCancelable(false);
		dialog.setPositiveButton("Live", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {
				Intent intent;
				intent = new Intent(mContext, TeamData.class);
				intent.putExtra("teamID", item.getTeamID());
				mContext.startActivity(intent);
			}
		});
		dialog.setNeutralButton("Info", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {
				Intent intent;
				intent = new Intent(mContext, TeamView.class);
				intent.putExtra("teamID", item.getTeamID());
				mContext.startActivity(intent);
			}
		});
		dialog.setNegativeButton("Close", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {
	                dialog.cancel();
			}
		});
		dialog.show();
	
		Log.i("ontap_index",""+index);
		return(true);
	}
}
